home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlb20 / lib / _mulsi3.s < prev    next >
Text File  |  1990-04-03  |  1KB  |  48 lines

  1. | long integer multiplication routine
  2. |
  3. | written by Kai-Uwe Bloem (I5110401@dbstu1.bitnet).
  4. |
  5. |
  6. | Revision 1.1, kub 03-90
  7. | first version, replaces the appropriate routine from fixnum.s.
  8. | This one is longer, but normally faster because __umulsi3 is no longer
  9. | called for multiplication. Rather, the code is inlined here. See the
  10. | comments in _umulsi3.s
  11.  
  12.     .text
  13.     .even
  14.     .globl    __mulsi3, ___mulsi3
  15.  
  16. __mulsi3:
  17. ___mulsi3:
  18.     movel    d2,a0        | save registers
  19.     movel    d3,a1
  20.     movemw    sp@(4),d0-d3    | get the two longs. u = d0-d1, v = d2-d3
  21.     movew    d0,sp@-        | sign flag
  22.     bpl    0f        | is u negative ?
  23.     negw    d1        | yes, force it positive
  24.     negxw    d0
  25. 0:    tstw    d2        | is v negative ?
  26.     bpl    0f
  27.     negw    d3        | yes, force it positive ...
  28.     negxw    d2
  29.     notw    sp@        |  ... and modify flag word
  30. 0:
  31.     extl    d0        | u.h <> 0 ?
  32.     beq    1f
  33.     mulu    d3,d0        | r  = v.l * u.h
  34. 1:    tstw    d2        | v.h <> 0 ?
  35.     beq    2f
  36.     mulu    d1,d2        | r += v.h * u.l
  37.     addw    d2,d0
  38. 2:    swap    d0
  39.     clrw    d0
  40.     mulu    d3,d1        | r += v.l * u.l
  41.     addl    d1,d0
  42.     movel    a1,d3
  43.     movel    a0,d2
  44.     tstw    sp@+        | should the result be negated ?
  45.     bpl    3f        | no, just return
  46.     negl    d0        | else r = -r
  47. 3:    rts
  48.